package com.april.pattern.behavioral.memento;

import lombok.*;

/**
 * @author April
 * @version V1.0.0
 * @date 2019/07/09 11:51
 * @description
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Article {
    private String title;

    private String content;

    private String images;

    /**
     * 转化为实际备忘存储的对象
     *
     * @return 实际备忘存储的对象
     */
    public ArticleMemento saveToMemento() {
        ArticleMemento articleMemento = new ArticleMemento(this.title,this.content,this.images);
        return articleMemento;
    }

    /**
     * 撤销
     * 将实际备忘存储对象转化为普通的Article
     *
     * @param articleMemento 实际备忘存储的对象
     */
    public void undoFromMemento(ArticleMemento articleMemento) {
        this.title = articleMemento.getTitle();
        this.content = articleMemento.getContent();
        this.images = articleMemento.getImages();
    }
}
